package JackSu.project_model;

/**
 * StrategyTest
 *
 * @author Syzer
 * @Description 策略模式
 * @Date 2021/7/9 16:40
 */
public class StrategyTest {

    private interface FailStrategy {
        void run();
    }

    private static class ExceptionRun implements FailStrategy {
        @Override
        public void run() {
            System.out.println("抛出异常");
        }
    }

    private static class DiscardRun implements FailStrategy {
        @Override
        public void run() {
            System.out.println("丢弃");
        }
    }

    private static class Apply {
        private FailStrategy failStrategy;

        public Apply(FailStrategy failStrategy) {
            this.failStrategy = failStrategy;
        }

        public void start() {
            System.out.println("开始执行");
            System.out.println("失败了……");
            failStrategy.run();
        }
    }

    public static void main(String[] args) {
        Apply apply = new Apply(new DiscardRun());
        apply.start();
    }
}
